package com.frostmourne.loreoriginex.builders;

import com.frostmourne.loreoriginex.LoreOriginEX;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarFlag;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;

import java.util.Map;

public class BossBarBuilder {

    public static BossBar barTemplate;

    private BossBar bossBar;
    private LivingEntity owner;


    public BossBarBuilder(LivingEntity owner) {
        this.owner = owner;
        this.bossBar =
                Bukkit.createBossBar(
                        barTemplate.getTitle()
                                .replace("<mobName>",owner.getName())
                                .replace("<health>",String.valueOf(owner.getHealth()))
                                .replace("<maxHealth>", String.valueOf(owner.getMaxHealth()))
                        ,barTemplate.getColor(),barTemplate.getStyle()
                );
    }
    /**
     * 获取
     * @return bossBar
     */
    public BossBar getBossBar() {
        return bossBar;
    }

    public BossBarBuilder setVisible(boolean is){
        bossBar.setVisible(is);
        return this;
    }
    public BossBarBuilder addPlayer(Player player){
        bossBar.addPlayer(player);
        return this;
    }

    public BossBarBuilder setProgress(double var){
        bossBar.setProgress(var);
        return this;
    }

    /**
     * 设置
     * @param bossBar
     */
    public void setBossBar(BossBar bossBar) {
        this.bossBar = bossBar;
    }

    /**
     * 获取
     * @return owner
     */
    public LivingEntity getOwner() {
        return owner;
    }

    /**
     * 设置
     * @param owner
     */
    public void setOwner(LivingEntity owner) {
        this.owner = owner;
    }

    public String toString() {
        return "BossBarBuilder{bossBar = " + bossBar + ", owner = " + owner + "}";
    }

    public static void load(){
        FileConfiguration config = LoreOriginEX.getInstance().getConfig();
        barTemplate = Bukkit.createBossBar(config.getString("Options.BossBar.BarName")
                , BarColor.valueOf(config.getString("Options.BossBar.Color").replace("&","§"))
                , BarStyle.valueOf(config.getString("Options.BossBar.Style"))
        );
    }
}
